/* 
 * Copyright (C)2008 Vladimir Hozjan vladimir.hozjan@gmail.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */

/**
 * @file  MainForm.h
 *
 * Main form for wxTetris application
 *
 * @author Vladimir Hozjan
 * @date   25.12.2008 
 *
 * @remarks VHOZ [25.12.2008]: File created
 */
#ifndef _wxMainForm_h_
#define _wxMainForm_h_

/////////////////////////////////////////////////////////////////////  LIBRARIES
#include <wx/wx.h>
#include "wx/dcbuffer.h"

class Tetris;
class MainForm;
/////////////////////////////////////////////////////////////  CLASS DECLARATION

class MyBoard : public wxPanel {
public:
  /// Constructor
  MyBoard(MainForm *parent, unsigned short aRow, unsigned short aCol, unsigned short aSize = 20 );

private:
  /// On paint callback method
  void onPaint(wxPaintEvent& event);

  /// On Erase background - is empty for performance reason
  void onEraseBackground(wxEraseEvent& event){}

  /// Key down events
  void onKeyDown(wxKeyEvent & aEvent);

  /// Draw rect
  void drawRect(wxBufferedPaintDC& dc, int x, int y, int color);

  /// Constructor
  MyBoard();

  /// Copy constructor
  MyBoard(MyBoard const &);

  const unsigned short mMaxRow;
  const unsigned short mMaxCol;
  const unsigned short mSize;
  const unsigned short mLineWidth;
  MainForm *mParent;

  DECLARE_EVENT_TABLE()
};


class MyNext : public wxPanel {
public:
  /// Constructor
  MyNext(MainForm *parent, unsigned short aMaxDimension,  unsigned short aSize = 20);

private:
  /// On paint callback method
  void onPaint(wxPaintEvent& event);

  /// On Erase background - is empty for performance reason
  void onEraseBackground(wxEraseEvent& event){}

  /// Draw rect
  void drawRect(wxBufferedPaintDC& dc, int x, int y, int color);

  /// Constructor
  MyNext();

  /// Copy constructor
  MyNext(MyBoard const &);

  const unsigned short mMaxRow;
  const unsigned short mMaxCol;
  const unsigned short mSize;
  const unsigned short mLineWidth;
  MainForm *mParent;

  DECLARE_EVENT_TABLE()
};

/**
 * @class MainForm
 *
 * @brief Main form for tetris game
 *
 * @author VHOZ
 *
 * @remarks VHOZ [25.12.2008]: Class created
 */
class MainForm : public wxFrame {
public:
  /// Destructor
  ~MainForm();;

  /// Constructor
  MainForm(const wxString &aName);

  /// Return tetris game
  Tetris * getTetris() const { return mTetris; }

protected:
private:

  /// Constructor
  MainForm();

  /// Copy constructor
  MainForm(MainForm const &);

  /// on tetris engine change
  void onTetrisChange();

  /// on new element appeared
  void onTetrisElementChange();

  /// Menu item quit
  void onNewGame(wxCommandEvent& aEvent);

  /// Menu item quit
  void onQuit(wxCommandEvent& aEvent);

  /// Timeout expired
  void onTimerExpired(wxTimerEvent & aEvent);

  wxTimer *mTimer;
  Tetris  *mTetris;
  MyBoard *mBoard;
  MyNext *mNext;
  wxStaticText *mScore;
  wxStaticText *mLevel;
  wxStaticText *mLines;
  wxBoxSizer *mTopsizer;

  DECLARE_EVENT_TABLE()
};

#endif // wxMainForm_h__
